home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / cli / mx2src.arc / PS.MOD < prev    next >
Text File  |  1989-01-05  |  9KB  |  265 lines

  1. (*$T-,$S-,$A+ *)
  2. MODULE  ps;
  3. FROM    SYSCALL IMPORT  SysVar,SysDes;
  4. FROM    GEMDOS  IMPORT  OldTerm,GetTime,GetDate,Alloc,Write;
  5. FROM    GEMX    IMPORT  BasePageAddress;
  6. FROM    SYSTEM  IMPORT  CODE,ADDRESS,ADR;
  7. FROM    Terminal        IMPORT  WriteString,WriteLn;
  8. FROM    XBIOS           IMPORT  SuperExec;
  9. FROM    ATOMIC          IMPORT  VERSION,SIGNAL,sysvariable,devicetype;
  10. FROM    Strings         IMPORT  String,Concat,Copy,Length;
  11. FROM    Conversions     IMPORT  ConvertToString;
  12. FROM    M2Conversions   IMPORT  ConvertCardinal,ConvertReal;
  13. FROM    BitStuff        IMPORT  WAnd,WShr;
  14. FROM    SCANNER         IMPORT  scinit,nxparm,ltext,etext,bkparm;
  15. FROM    TermBase        IMPORT  DoWrite,WriteProc;
  16.  
  17. CONST
  18.   SPACES   = "                                                        ";
  19.   TITLE1 = "       ";
  20.   TITLE2 = " Copyright LogicTek 1987,1988 Fred Brooks ";
  21.   PS1      =
  22. "  current            system    user      total CPU    total context  CRON";
  23.   PS2      =
  24. "  time     date      memory    memory    time         switches       timer";
  25.   PS3      =
  26. "  Name           PID PPID Status Pri Init Time          CPU time    PORT";
  27. VAR     temp,pstemp             :       String;
  28.         time,date               :       CARDINAL;
  29.         membot [432H]           :       LONGCARD;
  30.         memtop [436H]           :       LONGCARD;
  31.         hz200  [4baH]           :       LONGCARD;
  32.         s0,currentprocess       :       SIGNAL;
  33.         sysvar                  :       sysvariable;
  34.         done,dmode,stmode       :       BOOLEAN;
  35.         temphz200,topusermem,botusermem,usermemleft,memreserve
  36.                                 :       LONGCARD;
  37.  
  38.  
  39. PROCEDURE       FileWrite(char: CHAR);
  40. VAR     writecount      :       LONGCARD;
  41. BEGIN
  42.         writecount:=1;
  43.         Write(1,writecount,ADR(char));
  44. END             FileWrite;
  45.  
  46. (*$P- *)
  47. PROCEDURE       showmemory;
  48. VAR             memsize :       ADDRESS;
  49. BEGIN
  50.         topusermem:=memtop;
  51.         botusermem:=membot;
  52.         temphz200:=hz200;
  53.         Alloc(LONGCARD(-1),memsize);
  54.         usermemleft:=LONGCARD(memsize);
  55.         CODE(4e75H); (* rts *)
  56. END     showmemory;
  57. (*$P+ *)
  58.  
  59. (*$P- *)
  60. PROCEDURE       gettick;
  61. BEGIN
  62.         temphz200:=hz200;
  63.         CODE(4e75H); (* rts *)
  64. END     gettick;
  65. (*$P+ *)
  66.  
  67.  
  68. PROCEDURE       FormatTD(time: CARDINAL; date: CARDINAL);
  69. BEGIN
  70.            ConvertCardinal(CARDINAL(WShr(WAnd(time,63488),11)),2,temp);
  71.            WriteString(temp); (* hour *)
  72.            WriteString(":");
  73.  
  74.            ConvertCardinal(CARDINAL(WShr(WAnd(time,2016),5)),2,temp);
  75.            WriteString(temp); (* minute *)
  76.            WriteString(":");
  77.  
  78.            ConvertCardinal(2*CARDINAL(WAnd(time,31)),2,temp);
  79.            WriteString(temp); (* second *)
  80.            WriteString(" ");
  81.  
  82.            ConvertCardinal(CARDINAL(WShr(WAnd(date,480),5)),2,temp);
  83.            WriteString(temp); (* month *)
  84.            WriteString("/");
  85.  
  86.            ConvertCardinal(CARDINAL(WAnd(date,31)),2,temp);
  87.            WriteString(temp); (* day *)
  88.            WriteString("/");
  89.  
  90.            ConvertCardinal(80+CARDINAL(WShr(WAnd(date,65024),9)),2,temp);
  91.            WriteString(temp); (* year *)
  92.            WriteString("  ");
  93. END             FormatTD;
  94.  
  95. PROCEDURE       showtime(tick: LONGCARD);
  96. VAR             sec            :        REAL;
  97.                 min,hour       :        LONGCARD;
  98. BEGIN
  99.            sec:=FLOAT(tick);
  100.            sec:=sec/200.0;
  101.            min:=TRUNCD(sec) DIV 60;
  102.            hour:=min DIV 60;
  103.            min:=min-(hour*60);
  104.            ConvertToString(hour,10,FALSE,temp,done);
  105.            scinit(ADR(temp),SIZE(temp));
  106.            nxparm;
  107.            ltext(ADR(temp),SIZE(temp));
  108.            WriteString(temp);
  109.            WriteString(":");
  110.            ConvertToString(min,10,FALSE,temp,done);
  111.            scinit(ADR(temp),SIZE(temp));
  112.            nxparm;
  113.            ltext(ADR(temp),SIZE(temp));
  114.            WriteString(temp);
  115.            WriteString(":");
  116.            sec:=sec-FLOAT(min*60)-FLOAT(hour*3600);
  117.            ConvertReal(sec,11,3,temp);
  118.            scinit(ADR(temp),SIZE(temp));
  119.            nxparm;
  120.            ltext(ADR(temp),SIZE(temp));
  121.            WriteString(temp);
  122. END             showtime;
  123.  
  124. (* return time in seconds *)
  125. PROCEDURE       converttime(time: CARDINAL): LONGCARD;
  126. VAR                h,m,s           :           LONGCARD;
  127. BEGIN
  128.         h:=LONGCARD(WShr(WAnd(time,63488),11));  (* hours *)
  129.         m:=LONGCARD(WShr(WAnd(time,2016),5));    (* minutes *)
  130.         s:=2*LONGCARD(WAnd(time,31));            (* seconds *)
  131.         RETURN s+(m*60)+(h*3600);
  132. END             converttime;
  133.  
  134.  
  135. BEGIN
  136.            DoWrite:=WriteProc(FileWrite);
  137.            IF BasePageAddress^.CmdLine[2]='z' THEN stmode:=TRUE END;
  138.            SysDes(currentprocess);
  139.            SysVar(sysvar);
  140.            SuperExec(showmemory); (* return memsize *)
  141.            WriteLn;
  142.            WriteString(TITLE1);
  143.            WriteString(VERSION);
  144.            WriteString(TITLE2);
  145.            WriteLn;
  146.            GetTime(time);
  147.            GetDate(date);
  148.            WriteString(PS1);
  149.            WriteLn;
  150.            WriteString(PS2);
  151.            WriteLn;
  152.            WriteString("  ");
  153.            FormatTD(time,date);
  154.            ConvertToString(topusermem,10,FALSE,temp,done);
  155.            Copy(SPACES,0,10-Length(temp),pstemp);
  156.            Concat(temp,pstemp,temp);
  157.            WriteString(temp);
  158.            ConvertToString(usermemleft,10,FALSE,temp,done);
  159.            Copy(SPACES,0,10-Length(temp),pstemp);
  160.            Concat(temp,pstemp,temp);
  161.            WriteString(temp);
  162.            showtime(temphz200-sysvar.slicebegin^);
  163.            WriteString("    ");
  164.            ConvertToString(sysvar.contextswitch^,10,FALSE,temp,done);
  165.            Copy(SPACES,0,14-Length(temp),pstemp);
  166.            Concat(temp,pstemp,temp);
  167.            WriteString(temp);
  168.            IF sysvar.CronActive^ THEN
  169.               WriteString("ACTIVE");
  170.            ELSE
  171.               WriteString("INACTIVE");
  172.            END;
  173.            WriteLn;
  174.            WriteLn;
  175.            WriteString(PS3);
  176.            WriteLn;
  177.  
  178.            s0:=currentprocess;
  179.            REPEAT
  180.               IF s0^.pid#1 THEN
  181.                  s0:=s0^.next
  182.               END;
  183.            UNTIL s0^.pid=1;
  184.            REPEAT
  185.             WITH s0^ DO
  186.             IF stmode THEN
  187.                IF wsp=NIL THEN dmode:=TRUE ELSE dmode:=FALSE END;
  188.             ELSE
  189.                IF wsp#NIL THEN dmode:=TRUE ELSE dmode:=FALSE END;
  190.             END;
  191.             IF dmode THEN (* display *)
  192.               WriteString("  ");
  193.               Copy(SPACES,0,15-Length(name),pstemp);
  194.               Concat(name,pstemp,temp);
  195.               WriteString(temp);
  196.               ConvertCardinal(pid,2,temp);
  197.               WriteString(temp);
  198.               WriteString("  ");
  199.               ConvertCardinal(ppid,2,temp);
  200.               WriteString(temp);
  201.               WriteString("   ");
  202.               IF active THEN
  203.                  IF ready THEN
  204.                     WriteString("Run    ");
  205.                  ELSE
  206.                     WriteString("Ready  ");
  207.                  END;
  208.               ELSE
  209.                  IF wsp=NIL THEN
  210.                     WriteString("Inactive");
  211.                  ELSE
  212.                     WriteString("Sleep  ");
  213.                  END;
  214.               END;
  215.               ConvertCardinal(pri,2,temp);
  216.               WriteString(temp);
  217.               WriteString("  ");
  218.               FormatTD(time,date);
  219.               showtime(tick);
  220.               WriteString("  ");
  221.               CASE Iport OF
  222.                 printer :       WriteString("P"); |
  223.                 aux     :       WriteString("A"); |
  224.                 con     :       WriteString("C"); |
  225.                 midi    :       WriteString("M"); |
  226.                 null    :       WriteString("N"); |
  227.                 dev0    :       WriteString("0"); |
  228.                 dev1    :       WriteString("1"); |
  229.                 dev2    :       WriteString("2"); |
  230.                 dev3    :       WriteString("3"); |
  231.                 dev4    :       WriteString("4"); |
  232.                 dev5    :       WriteString("5"); |
  233.                 dev6    :       WriteString("6"); |
  234.                 dev7    :       WriteString("7"); |
  235.               END;
  236.               WriteString("/");
  237.               CASE Oport OF
  238.